home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 1999 #5 / 1999 CD 5 (black).iso / Delphi3 / install / data.z / WINSOCK.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-04  |  27.4 KB  |  776 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       Windows 32bit API Interface Unit                }
  6. {                                                       }
  7. {       Copyright (c) 1996,97 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit WinSock;
  12.  
  13. {$WEAKPACKAGEUNIT}
  14.  
  15. interface
  16.  
  17. uses Windows;
  18.  
  19. type
  20.   u_char = Char;
  21.   u_short = Word;
  22.   u_int = Integer;
  23.   u_long = Longint;
  24.  
  25. { The new type to be used in all
  26.   instances which refer to sockets. }
  27.   TSocket = u_int;
  28.  
  29. const
  30.   FD_SETSIZE     =   64;
  31.  
  32. type
  33.   PFDSet = ^TFDSet;
  34.   TFDSet = packed record
  35.     fd_count: u_int;
  36.     fd_array: array[0..FD_SETSIZE-1] of TSocket;
  37.   end;
  38.  
  39.   PTimeVal = ^TTimeVal;
  40.   TTimeVal = packed record
  41.     tv_sec: Longint;
  42.     tv_usec: Longint;
  43.   end;
  44.  
  45. const
  46.   IOCPARM_MASK = $7f;
  47.   IOC_VOID     = $20000000;
  48.   IOC_OUT      = $40000000;
  49.   IOC_IN       = $80000000;
  50.   IOC_INOUT    = (IOC_IN or IOC_OUT);
  51.  
  52.   FIONREAD     = IOC_OUT or { get # bytes to read }
  53.     ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
  54.     (Longint(Byte('f')) shl 8) or 127;
  55.   FIONBIO      = IOC_IN or { set/clear non-blocking i/o }
  56.     ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
  57.     (Longint(Byte('f')) shl 8) or 126;
  58.   FIOASYNC     = IOC_IN or { set/clear async i/o }
  59.     ((Longint(SizeOf(Longint)) and IOCPARM_MASK) shl 16) or
  60.     (Longint(Byte('f')) shl 8) or 125;
  61.  
  62. type
  63.   PHostEnt = ^THostEnt;
  64.   THostEnt = packed record
  65.     h_name: PChar;
  66.     h_aliases: ^PChar;
  67.     h_addrtype: Smallint;
  68.     h_length: Smallint;
  69.     case Byte of
  70.       0: (h_addr_list: ^PChar);
  71.       1: (h_addr: ^PChar)
  72.   end;
  73.  
  74.   PNetEnt = ^TNetEnt;
  75.   TNetEnt = packed record
  76.     n_name: PChar;
  77.     n_aliases: ^PChar;
  78.     n_addrtype: Smallint;
  79.     n_net: u_long;
  80.   end;
  81.  
  82.   PServEnt = ^TServEnt;
  83.   TServEnt = packed record
  84.     s_name: PChar;
  85.     s_aliases: ^PChar;
  86.     s_port: Smallint;
  87.     s_proto: PChar;
  88.   end;
  89.  
  90.   PProtoEnt = ^TProtoEnt;
  91.   TProtoEnt = packed record
  92.     p_name: PChar;
  93.     p_aliases: ^Pchar;
  94.     p_proto: Smallint;
  95.   end;
  96.  
  97. const
  98.  
  99. { Protocols }
  100.  
  101.   IPPROTO_IP     =   0;             { dummy for IP }
  102.   IPPROTO_ICMP   =   1;             { control message protocol }
  103.   IPPROTO_IGMP   =   2;             { group management protocol }
  104.   IPPROTO_GGP    =   3;             { gateway^2 (deprecated) }
  105.   IPPROTO_TCP    =   6;             { tcp }
  106.   IPPROTO_PUP    =  12;             { pup }
  107.   IPPROTO_UDP    =  17;             { user datagram protocol }
  108.   IPPROTO_IDP    =  22;             { xns idp }
  109.   IPPROTO_ND     =  77;             { UNOFFICIAL net disk proto }
  110.  
  111.   IPPROTO_RAW    =  255;            { raw IP packet }
  112.   IPPROTO_MAX    =  256;
  113.  
  114. { Port/socket numbers: network standard functions}
  115.  
  116.   IPPORT_ECHO    =   7;
  117.   IPPORT_DISCARD =   9;
  118.   IPPORT_SYSTAT  =   11;
  119.   IPPORT_DAYTIME =   13;
  120.   IPPORT_NETSTAT =   15;
  121.   IPPORT_FTP     =   21;
  122.   IPPORT_TELNET  =   23;
  123.   IPPORT_SMTP    =   25;
  124.   IPPORT_TIMESERVER  =  37;
  125.   IPPORT_NAMESERVER  =  42;
  126.   IPPORT_WHOIS       =  43;
  127.   IPPORT_MTP         =  57;
  128.  
  129. { Port/socket numbers: host specific functions }
  130.  
  131.   IPPORT_TFTP        =  69;
  132.   IPPORT_RJE         =  77;
  133.   IPPORT_FINGER      =  79;
  134.   IPPORT_TTYLINK     =  87;
  135.   IPPORT_SUPDUP      =  95;
  136.  
  137. { UNIX TCP sockets }
  138.   
  139.   IPPORT_EXECSERVER  =  512;
  140.   IPPORT_LOGINSERVER =  513;
  141.   IPPORT_CMDSERVER   =  514;
  142.   IPPORT_EFSSERVER   =  520;
  143.   
  144. { UNIX UDP sockets }
  145.  
  146.   IPPORT_BIFFUDP     =  512;
  147.   IPPORT_WHOSERVER   =  513;
  148.   IPPORT_ROUTESERVER =  520;
  149.   
  150. { Ports < IPPORT_RESERVED are reserved for
  151.   privileged processes (e.g. root). }
  152.  
  153.   IPPORT_RESERVED    =  1024;
  154.   
  155. { Link numbers }
  156.  
  157.   IMPLINK_IP         =  155;
  158.   IMPLINK_LOWEXPER   =  156;
  159.   IMPLINK_HIGHEXPER  =  158;
  160.  
  161. type
  162.   SunB = packed record
  163.     s_b1, s_b2, s_b3, s_b4: u_char;
  164.   end;
  165.  
  166.   SunW = packed record
  167.     s_w1, s_w2: u_short;
  168.   end;
  169.  
  170.   PInAddr = ^TInAddr;
  171.   TInAddr = packed record
  172.     case integer of
  173.       0: (S_un_b: SunB);
  174.       1: (S_un_w: SunW);
  175.       2: (S_addr: u_long);
  176.   end;
  177.  
  178.   PSockAddrIn = ^TSockAddrIn;
  179.   TSockAddrIn = packed record
  180.     case Integer of
  181.       0: (sin_family: u_short;
  182.           sin_port: u_short;
  183.           sin_addr: TInAddr;
  184.           sin_zero: array[0..7] of Char);
  185.       1: (sa_family: u_short;
  186.           sa_data: array[0..13] of Char)
  187.   end;
  188.  
  189. const
  190.   INADDR_ANY       = $00000000;
  191.   INADDR_LOOPBACK  = $7F000001;
  192.   INADDR_BROADCAST = $FFFFFFFF;
  193.   INADDR_NONE      = $FFFFFFFF;
  194.  
  195. const
  196.   WSADESCRIPTION_LEN     =   256;
  197.   WSASYS_STATUS_LEN      =   128;
  198.  
  199. type
  200.   PWSAData = ^TWSAData;
  201.   TWSAData = packed record
  202.     wVersion: Word;
  203.     wHighVersion: Word;
  204.     szDescription: array[0..WSADESCRIPTION_LEN] of Char;
  205.     szSystemStatus: array[0..WSASYS_STATUS_LEN] of Char;
  206.     iMaxSockets: Word;
  207.     iMaxUdpDg: Word;
  208.     lpVendorInfo: PChar;
  209.   end;
  210.  
  211.   PTransmitFileBuffers = ^TTransmitFileBuffers;
  212.   TTransmitFileBuffers = packed record
  213.       Head: Pointer;
  214.       HeadLength: DWORD;
  215.       Tail: Pointer;
  216.       TailLength: DWORD;
  217.   end;
  218.  
  219. const
  220.   TF_DISCONNECT           = $01; 
  221.   TF_REUSE_SOCKET         = $02; 
  222.   TF_WRITE_BEHIND         = $04; 
  223.  
  224. { Options for use with [gs]etsockopt at the IP level. }
  225.  
  226.   IP_OPTIONS          = 1;
  227.   IP_MULTICAST_IF     = 2;           { set/get IP multicast interface   }
  228.   IP_MULTICAST_TTL    = 3;           { set/get IP multicast timetolive  }
  229.   IP_MULTICAST_LOOP   = 4;           { set/get IP multicast loopback    }
  230.   IP_ADD_MEMBERSHIP   = 5;           { add  an IP group membership      }
  231.   IP_DROP_MEMBERSHIP  = 6;           { drop an IP group membership      }
  232.   IP_TTL              = 7;           { set/get IP Time To Live          }
  233.   IP_TOS              = 8;           { set/get IP Type Of Service       }
  234.   IP_DONTFRAGMENT     = 9;           { set/get IP Don't Fragment flag   }
  235.  
  236.  
  237.   IP_DEFAULT_MULTICAST_TTL   = 1;    { normally limit m'casts to 1 hop  }
  238.   IP_DEFAULT_MULTICAST_LOOP  = 1;    { normally hear sends if a member  }
  239.   IP_MAX_MEMBERSHIPS         = 20;   { per socket; must fit in one mbuf }
  240.  
  241. { This is used instead of -1, since the
  242.   TSocket type is unsigned.}
  243.  
  244.   INVALID_SOCKET        = TSocket(NOT(0));
  245.   SOCKET_ERROR            = -1;
  246.  
  247. { Types }
  248.  
  249.   SOCK_STREAM     = 1;               { stream socket }
  250.   SOCK_DGRAM      = 2;               { datagram socket }
  251.   SOCK_RAW        = 3;               { raw-protocol interface }
  252.   SOCK_RDM        = 4;               { reliably-delivered message }
  253.   SOCK_SEQPACKET  = 5;               { sequenced packet stream }
  254.  
  255. { Option flags per-socket. }
  256.  
  257.   SO_DEBUG        = $0001;          { turn on debugging info recording }
  258.   SO_ACCEPTCONN   = $0002;          { socket has had listen() }
  259.   SO_REUSEADDR    = $0004;          { allow local address reuse }
  260.   SO_KEEPALIVE    = $0008;          { keep connections alive }
  261.   SO_DONTROUTE    = $0010;          { just use interface addresses }
  262.   SO_BROADCAST    = $0020;          { permit sending of broadcast msgs }
  263.   SO_USELOOPBACK  = $0040;          { bypass hardware when possible }
  264.   SO_LINGER       = $0080;          { linger on close if data present }
  265.   SO_OOBINLINE    = $0100;          { leave received OOB data in line }
  266.  
  267.   SO_DONTLINGER  =   $ff7f;
  268.  
  269. { Additional options. }
  270.  
  271.   SO_SNDBUF       = $1001;          { send buffer size }
  272.   SO_RCVBUF       = $1002;          { receive buffer size }
  273.   SO_SNDLOWAT     = $1003;          { send low-water mark }
  274.   SO_RCVLOWAT     = $1004;          { receive low-water mark }
  275.   SO_SNDTIMEO     = $1005;          { send timeout }
  276.   SO_RCVTIMEO     = $1006;          { receive timeout }
  277.   SO_ERROR        = $1007;          { get error status and clear }
  278.   SO_TYPE         = $1008;          { get socket type }
  279.  
  280. { Options for connect and disconnect data and options.  Used only by
  281.   non-TCP/IP transports such as DECNet, OSI TP4, etc. }
  282.  
  283.   SO_CONNDATA     = $7000;
  284.   SO_CONNOPT      = $7001;
  285.   SO_DISCDATA     = $7002;
  286.   SO_DISCOPT      = $7003;
  287.   SO_CONNDATALEN  = $7004;
  288.   SO_CONNOPTLEN   = $7005;
  289.   SO_DISCDATALEN  = $7006;
  290.   SO_DISCOPTLEN   = $7007;
  291.  
  292. { Option for opening sockets for synchronous access. }
  293.  
  294.   SO_OPENTYPE     = $7008;
  295.  
  296.   SO_SYNCHRONOUS_ALERT    = $10;
  297.   SO_SYNCHRONOUS_NONALERT = $20;
  298.  
  299. { Other NT-specific options. }
  300.  
  301.   SO_MAXDG        = $7009;
  302.   SO_MAXPATHDG    = $700A;
  303.   SO_UPDATE_ACCEPT_CONTEXT     = $700B; 
  304.   SO_CONNECT_TIME = $700C; 
  305.  
  306. { TCP options. }
  307.  
  308.   TCP_NODELAY     = $0001;
  309.   TCP_BSDURGENT   = $7000;
  310.  
  311. { Address families. }
  312.  
  313.   AF_UNSPEC       = 0;               { unspecified }
  314.   AF_UNIX         = 1;               { local to host (pipes, portals) }
  315.   AF_INET         = 2;               { internetwork: UDP, TCP, etc. }
  316.   AF_IMPLINK      = 3;               { arpanet imp addresses }
  317.   AF_PUP          = 4;               { pup protocols: e.g. BSP }
  318.   AF_CHAOS        = 5;               { mit CHAOS protocols }
  319.   AF_IPX          = 6;               { IPX and SPX }
  320.   AF_NS           = 6;               { XEROX NS protocols }
  321.   AF_ISO          = 7;               { ISO protocols }
  322.   AF_OSI          = AF_ISO;          { OSI is ISO }
  323.   AF_ECMA         = 8;               { european computer manufacturers }
  324.   AF_DATAKIT      = 9;               { datakit protocols }
  325.   AF_CCITT        = 10;              { CCITT protocols, X.25 etc }
  326.   AF_SNA          = 11;              { IBM SNA }
  327.   AF_DECnet       = 12;              { DECnet }
  328.   AF_DLI          = 13;              { Direct data link interface }
  329.   AF_LAT          = 14;              { LAT }
  330.   AF_HYLINK       = 15;              { NSC Hyperchannel }
  331.   AF_APPLETALK    = 16;              { AppleTalk }
  332.   AF_NETBIOS      = 17;              { NetBios-style addresses }
  333.   AF_VOICEVIEW    = 18;              { VoiceView }
  334.   AF_FIREFOX      = 19;              { FireFox }
  335.   AF_UNKNOWN1     = 20;              { Somebody is using this! }
  336.   AF_BAN          = 21;              { Banyan }
  337.  
  338.   AF_MAX          = 22; 
  339.  
  340. type
  341.   { Structure used by kernel to store most addresses. }
  342.  
  343.   PSockAddr = ^TSockAddr;
  344.   TSockAddr = TSockAddrIn;
  345.  
  346.   { Structure used by kernel to pass protocol information in raw sockets. }
  347.   PSockProto = ^TSockProto;
  348.   TSockProto = packed record
  349.     sp_family: u_short;
  350.     sp_protocol: u_short;
  351.   end;
  352.  
  353. const
  354. { Protocol families, same as address families for now. }
  355.  
  356.   PF_UNSPEC       = AF_UNSPEC;
  357.   PF_UNIX         = AF_UNIX;
  358.   PF_INET         = AF_INET;
  359.   PF_IMPLINK      = AF_IMPLINK;
  360.   PF_PUP          = AF_PUP;
  361.   PF_CHAOS        = AF_CHAOS;
  362.   PF_NS           = AF_NS;
  363.   PF_IPX          = AF_IPX;
  364.   PF_ISO          = AF_ISO;
  365.   PF_OSI          = AF_OSI;
  366.   PF_ECMA         = AF_ECMA;
  367.   PF_DATAKIT      = AF_DATAKIT;
  368.   PF_CCITT        = AF_CCITT;
  369.   PF_SNA          = AF_SNA;
  370.   PF_DECnet       = AF_DECnet;
  371.   PF_DLI          = AF_DLI;
  372.   PF_LAT          = AF_LAT;
  373.   PF_HYLINK       = AF_HYLINK;
  374.   PF_APPLETALK    = AF_APPLETALK;
  375.   PF_VOICEVIEW    = AF_VOICEVIEW;
  376.   PF_FIREFOX      = AF_FIREFOX; 
  377.   PF_UNKNOWN1     = AF_UNKNOWN1; 
  378.   PF_BAN          = AF_BAN; 
  379.  
  380.   PF_MAX          = AF_MAX;
  381.  
  382. type
  383. { Structure used for manipulating linger option. }
  384.   PLinger = ^TLinger;
  385.   TLinger = packed record
  386.     l_onoff: u_short;
  387.     l_linger: u_short;
  388.   end;
  389.  
  390. const
  391. { Level number for (get/set)sockopt() to apply to socket itself. }
  392.  
  393.   SOL_SOCKET      = $ffff;          {options for socket level }
  394.  
  395. { Maximum queue length specifiable by listen. }
  396.  
  397.   SOMAXCONN       = 5;
  398.  
  399.   MSG_OOB         = $1;             {process out-of-band data }
  400.   MSG_PEEK        = $2;             {peek at incoming message }
  401.   MSG_DONTROUTE   = $4;             {send without using routing tables }
  402.  
  403.   MSG_MAXIOVLEN   = 16;
  404.  
  405.   MSG_PARTIAL     = $8000;          {partial send or recv for message xport }
  406.  
  407. { Define constant based on rfc883, used by gethostbyxxxx() calls. }
  408.  
  409.   MAXGETHOSTSTRUCT        = 1024;
  410.  
  411. { Define flags to be used with the WSAAsyncSelect() call. }
  412.  
  413.   FD_READ         = $01;
  414.   FD_WRITE        = $02;
  415.   FD_OOB          = $04;
  416.   FD_ACCEPT       = $08;
  417.   FD_CONNECT      = $10;
  418.   FD_CLOSE        = $20;
  419.  
  420. { All Windows Sockets error constants are biased by WSABASEERR from the "normal" }
  421.  
  422.   WSABASEERR              = 10000;
  423.  
  424. { Windows Sockets definitions of regular Microsoft C error constants }
  425.  
  426.   WSAEINTR                = (WSABASEERR+4);
  427.   WSAEBADF                = (WSABASEERR+9);
  428.   WSAEACCES               = (WSABASEERR+13);
  429.   WSAEFAULT               = (WSABASEERR+14);
  430.   WSAEINVAL               = (WSABASEERR+22);
  431.   WSAEMFILE               = (WSABASEERR+24);
  432.  
  433. { Windows Sockets definitions of regular Berkeley error constants }
  434.  
  435.   WSAEWOULDBLOCK          = (WSABASEERR+35);
  436.   WSAEINPROGRESS          = (WSABASEERR+36);
  437.   WSAEALREADY             = (WSABASEERR+37);
  438.   WSAENOTSOCK             = (WSABASEERR+38);
  439.   WSAEDESTADDRREQ         = (WSABASEERR+39);
  440.   WSAEMSGSIZE             = (WSABASEERR+40);
  441.   WSAEPROTOTYPE           = (WSABASEERR+41);
  442.   WSAENOPROTOOPT          = (WSABASEERR+42);
  443.   WSAEPROTONOSUPPORT      = (WSABASEERR+43);
  444.   WSAESOCKTNOSUPPORT      = (WSABASEERR+44);
  445.   WSAEOPNOTSUPP           = (WSABASEERR+45);
  446.   WSAEPFNOSUPPORT         = (WSABASEERR+46);
  447.   WSAEAFNOSUPPORT         = (WSABASEERR+47);
  448.   WSAEADDRINUSE           = (WSABASEERR+48);
  449.   WSAEADDRNOTAVAIL        = (WSABASEERR+49);
  450.   WSAENETDOWN             = (WSABASEERR+50);
  451.   WSAENETUNREACH          = (WSABASEERR+51);
  452.   WSAENETRESET            = (WSABASEERR+52);
  453.   WSAECONNABORTED         = (WSABASEERR+53);
  454.   WSAECONNRESET           = (WSABASEERR+54);
  455.   WSAENOBUFS              = (WSABASEERR+55);
  456.   WSAEISCONN              = (WSABASEERR+56);
  457.   WSAENOTCONN             = (WSABASEERR+57);
  458.   WSAESHUTDOWN            = (WSABASEERR+58);
  459.   WSAETOOMANYREFS         = (WSABASEERR+59);
  460.   WSAETIMEDOUT            = (WSABASEERR+60);
  461.   WSAECONNREFUSED         = (WSABASEERR+61);
  462.   WSAELOOP                = (WSABASEERR+62);
  463.   WSAENAMETOOLONG         = (WSABASEERR+63);
  464.   WSAEHOSTDOWN            = (WSABASEERR+64);
  465.   WSAEHOSTUNREACH         = (WSABASEERR+65);
  466.   WSAENOTEMPTY            = (WSABASEERR+66);
  467.   WSAEPROCLIM             = (WSABASEERR+67);
  468.   WSAEUSERS               = (WSABASEERR+68);
  469.   WSAEDQUOT               = (WSABASEERR+69);
  470.   WSAESTALE               = (WSABASEERR+70);
  471.   WSAEREMOTE              = (WSABASEERR+71);
  472.  
  473.   WSAEDISCON              = (WSABASEERR+101);
  474.  
  475. { Extended Windows Sockets error constant definitions }
  476.  
  477.   WSASYSNOTREADY          = (WSABASEERR+91);
  478.   WSAVERNOTSUPPORTED      = (WSABASEERR+92);
  479.   WSANOTINITIALISED       = (WSABASEERR+93);
  480.  
  481. { Error return codes from gethostbyname() and gethostbyaddr()
  482.   (when using the resolver). Note that these errors are
  483.   retrieved via WSAGetLastError() and must therefore follow
  484.   the rules for avoiding clashes with error numbers from
  485.   specific implementations or language run-time systems.
  486.   For this reason the codes are based at WSABASEERR+1001.
  487.   Note also that [WSA]NO_ADDRESS is defined only for
  488.   compatibility purposes. }
  489.  
  490. { Authoritative Answer: Host not found }
  491.  
  492.   WSAHOST_NOT_FOUND       = (WSABASEERR+1001);
  493.   HOST_NOT_FOUND          = WSAHOST_NOT_FOUND;
  494.  
  495. { Non-Authoritative: Host not found, or SERVERFAIL }
  496.  
  497.   WSATRY_AGAIN            = (WSABASEERR+1002);
  498.   TRY_AGAIN               = WSATRY_AGAIN;
  499.  
  500. { Non recoverable errors, FORMERR, REFUSED, NOTIMP }
  501.  
  502.   WSANO_RECOVERY          = (WSABASEERR+1003);
  503.   NO_RECOVERY             = WSANO_RECOVERY;
  504.  
  505. { Valid name, no data record of requested type }
  506.  
  507.   WSANO_DATA              = (WSABASEERR+1004);
  508.   NO_DATA                 = WSANO_DATA;
  509.  
  510. { no address, look for MX record }
  511.  
  512.   WSANO_ADDRESS           = WSANO_DATA;
  513.   NO_ADDRESS              = WSANO_ADDRESS;
  514.  
  515. { Windows Sockets errors redefined as regular Berkeley error constants.
  516.   These are commented out in Windows NT to avoid conflicts with errno.h.
  517.   Use the WSA constants instead. }
  518.  
  519.   EWOULDBLOCK        =  WSAEWOULDBLOCK;
  520.   EINPROGRESS        =  WSAEINPROGRESS;
  521.   EALREADY           =  WSAEALREADY;
  522.   ENOTSOCK           =  WSAENOTSOCK;
  523.   EDESTADDRREQ       =  WSAEDESTADDRREQ;
  524.   EMSGSIZE           =  WSAEMSGSIZE;
  525.   EPROTOTYPE         =  WSAEPROTOTYPE;
  526.   ENOPROTOOPT        =  WSAENOPROTOOPT;
  527.   EPROTONOSUPPORT    =  WSAEPROTONOSUPPORT;
  528.   ESOCKTNOSUPPORT    =  WSAESOCKTNOSUPPORT;
  529.   EOPNOTSUPP         =  WSAEOPNOTSUPP;
  530.   EPFNOSUPPORT       =  WSAEPFNOSUPPORT;
  531.   EAFNOSUPPORT       =  WSAEAFNOSUPPORT;
  532.   EADDRINUSE         =  WSAEADDRINUSE;
  533.   EADDRNOTAVAIL      =  WSAEADDRNOTAVAIL;
  534.   ENETDOWN           =  WSAENETDOWN;
  535.   ENETUNREACH        =  WSAENETUNREACH;
  536.   ENETRESET          =  WSAENETRESET;
  537.   ECONNABORTED       =  WSAECONNABORTED;
  538.   ECONNRESET         =  WSAECONNRESET;
  539.   ENOBUFS            =  WSAENOBUFS;
  540.   EISCONN            =  WSAEISCONN;
  541.   ENOTCONN           =  WSAENOTCONN;
  542.   ESHUTDOWN          =  WSAESHUTDOWN;
  543.   ETOOMANYREFS       =  WSAETOOMANYREFS;
  544.   ETIMEDOUT          =  WSAETIMEDOUT;
  545.   ECONNREFUSED       =  WSAECONNREFUSED;
  546.   ELOOP              =  WSAELOOP;
  547.   ENAMETOOLONG       =  WSAENAMETOOLONG;
  548.   EHOSTDOWN          =  WSAEHOSTDOWN;
  549.   EHOSTUNREACH       =  WSAEHOSTUNREACH;
  550.   ENOTEMPTY          =  WSAENOTEMPTY;
  551.   EPROCLIM           =  WSAEPROCLIM;
  552.   EUSERS             =  WSAEUSERS;
  553.   EDQUOT             =  WSAEDQUOT;
  554.   ESTALE             =  WSAESTALE;
  555.   EREMOTE            =  WSAEREMOTE;
  556.  
  557.  
  558. { Socket function prototypes }
  559.  
  560. function accept(s: TSocket; addr: PSockAddr; addrlen: PInteger): TSocket; stdcall;
  561. function bind(s: TSocket; var addr: TSockAddr; namelen: Integer): Integer; stdcall;
  562. function closesocket(s: TSocket): Integer; stdcall;
  563. function connect(s: TSocket; var name: TSockAddr; namelen: Integer): Integer; stdcall;
  564. function ioctlsocket(s: TSocket; cmd: Longint; var arg: u_long): Integer; stdcall;
  565. function getpeername(s: TSocket; var name: TSockAddr; var namelen: Integer): Integer; stdcall;
  566. function getsockname(s: TSocket; var name: TSockAddr; var namelen: Integer): Integer; stdcall;
  567. function getsockopt(s: TSocket; level, optname: Integer; optval: PChar; var optlen: Integer): Integer; stdcall;
  568. function htonl(hostlong: u_long): u_long; stdcall;
  569. function htons(hostshort: u_short): u_short; stdcall;
  570. function inet_addr(cp: PChar): u_long; stdcall; {PInAddr;}  { TInAddr }
  571. function inet_ntoa(inaddr: TInAddr): PChar; stdcall;
  572. function listen(s: TSocket; backlog: Integer): Integer; stdcall;
  573. function ntohl(netlong: u_long): u_long; stdcall;
  574. function ntohs(netshort: u_short): u_short; stdcall;
  575. function recv(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
  576. function recvfrom(s: TSocket; var Buf; len, flags: Integer;
  577.   var from: TSockAddr; var fromlen: Integer): Integer; stdcall;
  578. function select(nfds: Integer; readfds, writefds, exceptfds: PFDSet;
  579.   timeout: PTimeVal): Longint; stdcall;
  580. function send(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
  581. function sendto(s: TSocket; var Buf; len, flags: Integer; var addrto: TSockAddr;
  582.   tolen: Integer): Integer; stdcall;
  583. function setsockopt(s: TSocket; level, optname: Integer; optval: PChar;
  584.   optlen: Integer): Integer; stdcall;
  585. function shutdown(s: TSocket; how: Integer): Integer; stdcall;
  586. function socket(af, struct, protocol: Integer): TSocket; stdcall;
  587. function gethostbyaddr(addr: Pointer; len, struct: Integer): PHostEnt; stdcall;
  588. function gethostbyname(name: PChar): PHostEnt; stdcall;
  589. function gethostname(name: PChar; len: Integer): Integer; stdcall;
  590. function getservbyport(port: Integer; proto: PChar): PServEnt; stdcall;
  591. function getservbyname(name, proto: PChar): PServEnt; stdcall;
  592. function getprotobynumber(proto: Integer): PProtoEnt; stdcall;
  593. function getprotobyname(name: PChar): PProtoEnt; stdcall;
  594. function WSAStartup(wVersionRequired: word; var WSData: TWSAData): Integer; stdcall;
  595. function WSACleanup: Integer; stdcall;
  596. procedure WSASetLastError(iError: Integer); stdcall;
  597. function WSAGetLastError: Integer; stdcall;
  598. function WSAIsBlocking: BOOL; stdcall;
  599. function WSAUnhookBlockingHook: Integer; stdcall;
  600. function WSASetBlockingHook(lpBlockFunc: TFarProc): TFarProc; stdcall;
  601. function WSACancelBlockingCall: Integer; stdcall;
  602. function WSAAsyncGetServByName(HWindow: HWND; wMsg: u_int; 
  603.   name, proto, buf: PChar; buflen: Integer): THandle; stdcall;
  604. function WSAAsyncGetServByPort( HWindow: HWND; wMsg, port: u_int; 
  605.   proto, buf: PChar; buflen: Integer): THandle; stdcall;
  606. function WSAAsyncGetProtoByName(HWindow: HWND; wMsg: u_int;
  607.   name, buf: PChar; buflen: Integer): THandle; stdcall;
  608. function WSAAsyncGetProtoByNumber(HWindow: HWND; wMsg: u_int; number: Integer;
  609.   buf: PChar; buflen: Integer): THandle; stdcall;
  610. function WSAAsyncGetHostByName(HWindow: HWND; wMsg: u_int; 
  611.   name, buf: PChar; buflen: Integer): THandle; stdcall;
  612. function WSAAsyncGetHostByAddr(HWindow: HWND; wMsg: u_int; addr: PChar; 
  613.   len, struct: Integer; buf: PChar; buflen: Integer): THandle; stdcall;
  614. function WSACancelAsyncRequest(hAsyncTaskHandle: THandle): Integer; stdcall;
  615. function WSAAsyncSelect(s: TSocket; HWindow: HWND; wMsg: u_int; lEvent: Longint): Integer; stdcall;
  616. function WSARecvEx(s: TSocket; var buf; len: Integer; var flags: Integer): Integer; stdcall;
  617. function __WSAFDIsSet(s: TSOcket; var FDSet: TFDSet): Bool; stdcall;
  618.  
  619. function TransmitFile(hSocket: TSocket; hFile: THandle; nNumberOfBytesToWrite: DWORD;
  620.   nNumberOfBytesPerSend: DWORD; lpOverlapped: POverlapped;
  621.   lpTransmitBuffers: PTransmitFileBuffers; dwReserved: DWORD): BOOL; stdcall;
  622.  
  623. function AcceptEx(sListenSocket, sAcceptSocket: TSocket;
  624.   lpOutputBuffer: Pointer; dwReceiveDataLength, dwLocalAddressLength, 
  625.   dwRemoteAddressLength: DWORD; var lpdwBytesReceived: DWORD; 
  626.   lpOverlapped: POverlapped): BOOL; stdcall;
  627.  
  628. procedure GetAcceptExSockaddrs(lpOutputBuffer: Pointer; 
  629.   dwReceiveDataLength, dwLocalAddressLength, dwRemoteAddressLength: DWORD; 
  630.   var LocalSockaddr: TSockAddr; var LocalSockaddrLength: Integer; 
  631.   var RemoteSockaddr: TSockAddr; var RemoteSockaddrLength: Integer); stdcall;
  632.  
  633. function WSAMakeSyncReply(Buflen, Error: Word): Longint;
  634. function WSAMakeSelectReply(Event, Error: Word): Longint;
  635. function WSAGetAsyncBuflen(Param: Longint): Word;
  636. function WSAGetAsyncError(Param: Longint): Word;
  637. function WSAGetSelectEvent(Param: Longint): Word;
  638. function WSAGetSelectError(Param: Longint): Word;
  639.  
  640. procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet);
  641. function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean;
  642. procedure FD_SET(Socket: TSocket; var FDSet: TFDSet);
  643. procedure FD_ZERO(var FDSet: TFDSet);
  644.  
  645. implementation
  646.  
  647. const
  648.   winsocket = 'wsock32.dll';
  649.  
  650. function WSAMakeSyncReply;
  651. begin
  652.   WSAMakeSyncReply:= MakeLong(Buflen, Error);
  653. end;
  654.  
  655. function WSAMakeSelectReply;
  656. begin
  657.   WSAMakeSelectReply:= MakeLong(Event, Error);
  658. end;
  659.  
  660. function WSAGetAsyncBuflen;
  661. begin
  662.   WSAGetAsyncBuflen:= LOWORD(Param);
  663. end;
  664.  
  665. function WSAGetAsyncError;
  666. begin
  667.   WSAGetAsyncError:= HIWORD(Param);
  668. end;
  669.  
  670. function WSAGetSelectEvent;
  671. begin
  672.   WSAGetSelectEvent:= LOWORD(Param);
  673. end;
  674.  
  675. function WSAGetSelectError;
  676. begin
  677.   WSAGetSelectError:= HIWORD(Param);
  678. end;
  679.  
  680. procedure FD_CLR(Socket: TSocket; var FDSet: TFDSet);
  681. var
  682.   I: Integer;
  683. begin
  684.   I := 0;
  685.   while I < FDSet.fd_count do
  686.   begin
  687.     if FDSet.fd_array[I] = Socket then
  688.     begin
  689.       while I < FDSet.fd_count - 1 do
  690.       begin
  691.         FDSet.fd_array[I] := FDSet.fd_array[I + 1];
  692.         Inc(I);
  693.       end;
  694.       Dec(FDSet.fd_count);
  695.       Break;
  696.     end;
  697.     Inc(I);
  698.   end;
  699. end;
  700.  
  701. function FD_ISSET(Socket: TSocket; var FDSet: TFDSet): Boolean;
  702. begin
  703.   Result := __WSAFDIsSet(Socket, FDSet);
  704. end;
  705.  
  706. procedure FD_SET(Socket: TSocket; var FDSet: TFDSet);
  707. begin
  708.   if FDSet.fd_count < FD_SETSIZE then
  709.   begin
  710.     FDSet.fd_array[FDSet.fd_count] := Socket;
  711.     Inc(FDSet.fd_count);
  712.   end;  
  713. end;
  714.  
  715. procedure FD_ZERO(var FDSet: TFDSet);
  716. begin
  717.   FDSet.fd_count := 0;
  718. end;
  719.  
  720. function accept;            external    winsocket name 'accept';
  721. function bind;              external    winsocket name 'bind';
  722. function closesocket;       external    winsocket name 'closesocket';
  723. function connect;           external    winsocket name 'connect';
  724. function getpeername;       external    winsocket name 'getpeername';
  725. function getsockname;       external    winsocket name 'getsockname';
  726. function getsockopt;        external    winsocket name 'getsockopt';
  727. function htonl;             external    winsocket name 'htonl';
  728. function htons;             external    winsocket name 'htons';
  729. function inet_addr;         external    winsocket name 'inet_addr';
  730. function inet_ntoa;         external    winsocket name 'inet_ntoa';
  731. function ioctlsocket;       external    winsocket name 'ioctlsocket';
  732. function listen;            external    winsocket name 'listen';
  733. function ntohl;             external    winsocket name 'ntohl';
  734. function ntohs;             external    winsocket name 'ntohs';
  735. function recv;              external    winsocket name 'recv';
  736. function recvfrom;          external    winsocket name 'recvfrom';
  737. function select;            external    winsocket name 'select';
  738. function send;              external    winsocket name 'send';
  739. function sendto;            external    winsocket name 'sendto';
  740. function setsockopt;        external    winsocket name 'setsockopt';
  741. function shutdown;          external    winsocket name 'shutdown';
  742. function socket;            external    winsocket name 'socket';
  743.  
  744. function gethostbyaddr;     external    winsocket name 'gethostbyaddr';
  745. function gethostbyname;     external    winsocket name 'gethostbyname';
  746. function getprotobyname;    external    winsocket name 'getprotobyname';
  747. function getprotobynumber;  external    winsocket name 'getprotobynumber';
  748. function getservbyname;     external    winsocket name 'getservbyname';
  749. function getservbyport;     external    winsocket name 'getservbyport';
  750. function gethostname;       external    winsocket name 'gethostname';
  751.  
  752. function WSAAsyncSelect;    external    winsocket name 'WSAAsyncSelect';
  753. function WSARecvEx;         external    winsocket name 'WSARecvEx';
  754. function WSAAsyncGetHostByAddr; external winsocket name 'WSAAsyncGetHostByAddr';
  755. function WSAAsyncGetHostByName; external winsocket name 'WSAAsyncGetHostByName';
  756. function WSAAsyncGetProtoByNumber; external winsocket name 'WSAAsyncGetProtoByNumber';
  757. function WSAAsyncGetProtoByName; external winsocket name 'WSAAsyncGetProtoByName';
  758. function WSAAsyncGetServByPort; external winsocket name 'WSAAsyncGetServByPort';
  759. function WSAAsyncGetServByName; external winsocket name 'WSAAsyncGetServByName';
  760. function WSACancelAsyncRequest; external winsocket name 'WSACancelAsyncRequest';
  761. function WSASetBlockingHook; external    winsocket name 'WSASetBlockingHook';
  762. function WSAUnhookBlockingHook; external winsocket name 'WSAUnhookBlockingHook';
  763. function WSAGetLastError;    external    winsocket name 'WSAGetLastError';
  764. procedure WSASetLastError;   external    winsocket name 'WSASetLastError';
  765. function WSACancelBlockingCall; external winsocket name 'WSACancelBlockingCall';
  766. function WSAIsBlocking;     external     winsocket name 'WSAIsBlocking';
  767. function WSAStartup;        external     winsocket name 'WSAStartup';
  768. function WSACleanup;        external     winsocket name 'WSACleanup';
  769. function __WSAFDIsSet;      external     winsocket name '__WSAFDIsSet';
  770.  
  771. function TransmitFile;      external     winsocket name 'TransmitFile';
  772. function AcceptEx;          external     winsocket name 'AcceptEx';
  773. procedure GetAcceptExSockaddrs;  external    winsocket name 'GetAcceptExSockaddrs';
  774.  
  775. end.
  776.